package me.zhengjie.tool;

import java.util.List;
import java.util.Map;

public class ConditionUtil {
    public static void isTrueThrowException(boolean expression,String msg){
        if (expression){
            throw new IllegalArgumentException(msg);
        }
    }
    public static void listShouldOnlyOne(List list,String listInfo){
        if (ValidateUtil.isEmpty(list)){
            throw new IllegalArgumentException("没有获取到"+listInfo);
        }
        if (list.size() > 1){
            throw new IllegalArgumentException(listInfo+"存在多条");
        }
    }
    public static Map listsGetFirst(List<? extends Map> list,String listInfo){
        listShouldOnlyOne(list,listInfo);
        return list.get(0);
    }
    public static void listShouldOnlyOneOrNull(List list,String listInfo){
        if (list != null && list.size() > 1){
            throw new IllegalArgumentException(listInfo);
        }
    }
    public static Map listsGetFirstOrNull(List<? extends Map> list,String listInfo){
        listShouldOnlyOneOrNull(list,listInfo);
        if (list == null){
            return null;
        }else {
            return list.get(0);
        }
    }
}
